/**
 * @file tm1640.h
 * @author  xiaowine (xiaowine@sina.cn)
 * @brief
 * @version 01.00
 * @date    2022-03-02
 *
 * @copyright Copyright (c) {2020}  xiaowine
 *
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2022-03-02 <td>1.0     <td>wangh     <td>内容
 * </table>
 * ******************************************************************
 * *                   .::::
 * *                 .::::::::
 * *                ::::::::::
 * *             ..:::::::::::
 * *          '::::::::::::
 * *            .:::::::::
 * *       '::::::::::::::..        女神助攻,流量冲天
 * *            ..::::::::::::.     永不宕机,代码无bug
 * *          ``:::::::::::::::
 * *           ::::``:::::::::'        .:::
 * *          ::::'   ':::::'       .::::::::
 * *        .::::'      ::::     .:::::::'::::
 * *       .:::'       :::::  .:::::::::' ':::::
 * *      .::'        :::::.:::::::::'      ':::::
 * *     .::'         ::::::::::::::'         ``::::
 * * ...:::           ::::::::::::'              ``::
 * *```` ':.          ':::::::::'                  ::::.
 * *                   '.:::::'                    ':'````.
 * ******************************************************************
 */

#ifndef __TM1640_H_
#define __TM1640_H_
/* Private includes ----------------------------------------------------------*/
#include <stdint.h>
#include "stm32g0xx_hal.h"
/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/
#define TM1640_DIN(x) HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, (GPIO_PinState)x)
#define TM1640_SCK(x) HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, (GPIO_PinState)x)

#define ADDR_START1640 0XC0

#define DSP1640_DIS 0
#define DSP1640_ENB 1

/*
控制显示
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f 分别对应
1/16,  2/16,  4/16,  10/16, 11/16, 12/16, 13/16, 14/16

设置数据，0x40,0x44分别对应地址自动加一和固定地址模式
*/

#define SET_DATA_ORDER  0X40  //数据命令设置 地址自动加1
#define SET_DISPLAY     0X8F  //显示命令控制  脉冲宽度14/16
#define SET_DSP1640_DIS 0x80  //显示关控制

#define VT_DLY1640 15  // 80//10//2000
#define VT_DLYNOP  10  // 80//10

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
extern unsigned char const ch_table[];
/* Private function prototypes -----------------------------------------------*/

/* Private user code ---------------------------------------------------------*/

void TM1640_GPIO_Config(void);
void Nop1640(uint16_t T_Dly);
void TM1640Start(void);
void TM1640Stop(void);
void TM1640WriteByte(uint8_t date);
void TM1640_Init(uint8_t InValue);
void TM1640_SendData(uint8_t Addr1640, uint8_t *a, uint8_t DataLong);

#endif
